from typing import Union, Tuple, Optional, Dict

import requests


class InnerRegistryHttpClient:
    def __init__(self,
                 base_url: str,
                 cert: Union[str, Tuple[str, str]] = None,
                 verify: bool = True,
                 authorization: Optional[str] = None):
        self.base_url = base_url
        self.cert = cert
        self.verify = verify
        self.authorization = authorization

    def get(self, endpoint: str, **kwargs) -> requests.Response:
        return self.request('GET', endpoint, **kwargs)

    def request(self, method: str, endpoint: str, headers: Optional[Dict[str, str]] = None,
                allow_redirects=True) -> requests.Response:
        headers = headers or {}

        if self.authorization:
            headers['Authorization'] = self.authorization

        url = f"{self.base_url}/{endpoint}"

        return requests.request(method, url, headers=headers, cert=self.cert, verify=self.verify,
                                allow_redirects=allow_redirects)
